Skip to content

nixos timezone: set /etc/timezone which is needed by python#14285

Closed
peterhoeg wants to merge 1 commit intoNixOS:release-16.03from
peterhoeg:timezone
Closed

nixos timezone: set /etc/timezone which is needed by python#14285
peterhoeg wants to merge 1 commit intoNixOS:release-16.03from
peterhoeg:timezone

Conversation

@peterhoeg
Copy link
Member

Turns out python programs will try to read /etc/timezone or TZ. If neither is set, they will fall back to UTC.

/etc/timezone is no longer mentioned in the FHS though so I am honestly not sure if this is the right way forward.

Things done:
  • Tested using sandboxing (nix-build --option build-use-chroot true or nix.useChroot on NixOS)
  • Built on platform(s)
    • NixOS
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @edolstra, @cpages and @peti to be potential reviewers

@peti
Copy link
Member

peti commented Mar 29, 2016 via email

@peterhoeg
Copy link
Member Author

I've noticed in a python package I created that it was unable to detect the timezone and then fell back to UTC. If I set the TZ variable in the systemd unit file, then it was working correctly.

So maybe it's because the python wrapper doesn't set it correctly and that's the real issue?

On my Arch Linux box, /etc/timezone is created, so I'm imagining there is other software out there that reads that file, so maybe for the sake of compatbility we should do this?

@peti
Copy link
Member

peti commented Mar 29, 2016

If I set the TZ variable in the systemd unit file, then it was working correctly.

Yes, you need to set $TZ in the systemd unit file, otherwise it won't be set.

So maybe it's because the python wrapper doesn't set it correctly and that's the real issue?

I don't believe that Python wrapper scripts ought to be responsible for the $TZ variable.

On my Arch Linux box, /etc/timezone is created, so I'm imagining there is other software out there that reads that file, so maybe for the sake of compatbility we should do this?

No, we want to avoid hidden global state as much as possible. The proper solution is to set $TZ in the systemd unit file that runs your script.

@jagajaga
Copy link
Member

I agree with @peti.

@peterhoeg
Copy link
Member Author

I get your point about wanting to minimize global state, but we are already creating /etc/localtime which is "global timezone state" and this is just another way to represent the same thing for applications that for some reason do not use /etc/localtime. We are not polluting anything or adding any hidden depedencies.

@edolstra
Copy link
Member

Where exactly does Python use /etc/timezone? Grepping the Python 2 sources didn't turn up anything, and Python seems to detect my timezone fine:

>>> import time
>>> print time.tzname
('CET', 'CEST')

@peterhoeg
Copy link
Member Author

I noticed when doing #14262 that flexget wouldn't automatically pick up the timezone without the TZ variable being set (or the file being present).I don't know if this is a fault of flexget, one of its modules or python. I admittedly should have looked into that first before going ahead with this PR, but as mentioned, I noticed it on Arch Linux, so I simply assumed that /etc/timezone was simply missing. I'm happy regardless of which way this goes.

@grahamc
Copy link
Member

grahamc commented Mar 30, 2016

I propose we close this issue, as python core (3.5 tested locally) doesn't appear to use it, as tested via strace.

@joachifm joachifm closed this Mar 30, 2016
@peterhoeg peterhoeg deleted the timezone branch May 22, 2016 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants